﻿function showSSNMenu(loanID,ssn){
	var e = event.srcElement;
	var menu = new DropMenu("mnuFly");
	if( !menu.menuID )return false;
	menu.imageStyle += ";margin-top:0px;margin-bottom:0px";
	menu.add("InstantID","showInstantID(\""+loanID+"\")");
	menu.add("People Search","goPeopleSearch(\""+ssn+"\")");
	menu.add("People At Work","goPeopleAtWork(\""+ssn+"\")");
	menu.menuShow(getLeftPos(e),event.y-event.offsetY+e.offsetHeight-3);
	event.cancelBubble = true;
	return false;
}
function changeHome(phone,borrowerID){
	return changePhone("PhoneHome",phone,"Home Phone",borrowerID);
}
function changeWork(phone,borrowerID){
	return changePhone("PhoneWork",phone,"Work Phone",borrowerID);
}
function changeCell(phone,borrowerID){
	return changePhone("PhoneCell",phone,"Cell Phone",borrowerID);
}
function changeStreet(street,borrowerID){
	return changePhone("Street",street,"Street",borrowerID);
}
function changeCity(city,borrowerID){
	return changePhone("CityName",city,"City",borrowerID);
}
function changeState(state,borrowerID){
	return changePhone("stateCode",state,"State",borrowerID);
}
function changeZip(zip,borrowerID){
	return changePhone("Zip",zip,"Zip",borrowerID);
}
function changePhone(Name,Value,message,borrowerID){
	if( !confirm("Change "+message+"?") )return false;
	var ret = WS(CO("Borrower_Update"),Name,Value,borrowerID);
	if( showSOAPError(ret) )return false;
	alert(message+" was updated.");
	return true;
}
function openTasks() {
  var openOptions = "location=no,toolbar=no,resizable=yes,scrollbars=yes";
  var dialogOptions = "resizable:1";
  open('/manager/todo/todo.aspx?ShowSelf=1', "Tasks", openOptions);
}
function showWelcomeLetter(applID) {
	open("/Manager/Documents/BayQuest/Letters/WelcomeLetter.aspx?ApplID="+applID);
}
function showTitle(vin){return;
	WSA.Admin.FetchTitleByVIN(vin,_showTitle);
	function _showTitle(result){
		if( result.length == 1 && result[0].length < 100 )return showTitle(vin);
		var lienHolder = result.length>1?"Lien Holder: "+result[0]:"There is no Lien Holder on Title.";
		showModelessDialog("/include/ShowFrame.htm",{html:result[result.length-1],alert:lienHolder},"dialogWidth:700px;dialogHeight:550px;resizable:1");
	}
}
function goPeopleSearch(ssn){
	WSA.Admin.Accurint_GoPeopleSearch(ssn,function(result){showAccurintSearch(result,ssn)});
}
function goPeopleAtWork(ssn){
	WSA.Admin.Accurint_GoPeopleAtWork(ssn,function(result){showAccurintSearch(result,ssn)});
}
function showAccurintSearch(result,ssn){
	var re = new RegExp(".*"+ssn+"[\\s\\S]*");
	var raw = getRSfromDS(result).Fields("Raw").value.match(re);
	raw = raw[0].replace(/-\s\n/g,"- ").replace(/\s(\s)/g,"$1");
	raw = raw.replace(/[*]{20,}/g,"*******************************************").trim();
	showModelessDialog("/include/Alert.htm",{text:"<pre style='font-size:75%'>"+raw+"</pre>"});
}
function showGoogle(search){
	showModelessDialog("http://www.google.com/search?hl=en&q="+escape(search),null,"dialogWidth:600px;dialogHeight:400px;resizable:1");
}
function showCollectionLetters(letter,filter){
	//var w = showCollectionLetters.w || {};
	//if( w.closed === false )w.close();
	showCollectionLetters.w =open("/Manager/Documents/Letter.aspx?Letter=" + letter + "&" + filter);
	//showCollectionLetters.w.focus();
}
function saveFilter() {
    var filterDefault = ddlFilters()[ddlFilters().selectedIndex].text;
    var filterName = prompt('Profile: ' + ddlUsers()[ddlUsers().selectedIndex].Text + '. Filter (S:Xxxxx for shared filter):', filterDefault);
    if (filterName === null) return false;
    var m = filterName.match(/(.+?)?(?:\s*\{(.+)\})?$/);
    hdnFilterUser().value = m[2];
    hdnFilterName().value = filterName;
    return true;
}
var SELECT_LETTER_MSG = "Select a letter first.";